<template>
	<view class="more-set-box">
		<view class="top ">
			<view @click="goBack" class="arrowleft">
				<uni-icons type="arrowleft"></uni-icons>
			</view>
			<view class="top-title">
				阅读设置
			</view>
			<view class="blank">xxx</view>
		</view>
		<view>
			<view>行间距</view>
			<my-radios @choose="choose" :options="lines"></my-radios>
			<view>页边距</view>
			<my-radios @choose="choosePadding" :options="paddings"></my-radios>
		</view>
		<view v-html="html"></view>
	</view>
</template>

<script>
	import _tool from '@/util/tool.js';
	export default {
		data() {
			return {
				html: '',
				config: [],
				lines: [
					{
						name: '最小',
						size: 20,
						checked: true
					},
					{
						name: '较小',
						size: 22,
						checked: false
					},
					{
						name: '适中',
						size: 24,
						checked: false
					},
					{
						name: '较大',
						size: 26,
						checked: false
					},
					{
						name: '最大',
						size: 28,
						checked: false
					}
				],
				paddings: [
					{
						name: '最小',
						size: 10,
						checked: true
					},
					{
						name: '较小',
						size: 13,
						checked: false
					},
					{
						name: '适中',
						size: 16,
						checked: false
					},
					{
						name: '较大',
						size: 19,
						checked: false
					},
					{
						name: '最大',
						size: 21,
						checked: false
					}
				],
			}
		},
		onLoad() {
			try{
				var lineheight = uni.getStorageSync('lineheight')
				var padding = uni.getStorageSync('padding')
				if (lineheight) {
					for (var i = 0; i < this.lines.length; i++) {
						if (this.lines[i].size == lineheight) {
							// 选中
							this.lines[i].checked = true
						} else {
							this.lines[i].checked = false
						}
					}
				}
				if (padding) {
					for (var i = 0; i < this.paddings.length; i++) {
						if (this.paddings[i].size == padding) {
							// 选中
							this.paddings[i].checked = true
						} else {
							this.paddings[i].checked = false
						}
					}
				}
			}catch(e){
				//TODO handle the exception
				console.log(e)
			}
			
			
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			
			choose(e) {
				for (var i = 0; i < this.lines.length; i++) {
					if (i == e) {
						// 选中
						this.lines[i].checked = true
						// 添加到缓存
						uni.setStorageSync('lineheight', this.lines[i].size)
					} else {
						this.lines[i].checked = false
					}
				}
			},
			
			choosePadding(e) {
				for (var i = 0; i < this.paddings.length; i++) {
					if (i == e) {
						this.paddings[i].checked = true
						uni.setStorageSync('padding', this.paddings[i].size)
					} else {
						this.paddings[i].checked = false
					}
				}
			}
		}
		
	}
</script>
	
<style>
	.more-set-box {
		padding: 0 30rpx;
	}
	.top {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 200rpx;
		text-align: center;
	}
	
	.top-title {
		font-size: 40rpx;
		font-weight: bold;
	}
	
	.arrowleft {
		/* padding-right: 30rpx; */
	}
	.blank {
		color: #fff;
	}
</style>
